package com.zhuiyun.project.api.collectVideo.service.impl;

import com.zhuiyun.project.api.collectVideo.entity.CollectVideo;
import com.zhuiyun.project.api.collectVideo.entity.Favorites;
import com.zhuiyun.project.api.collectVideo.mapper.CollectVideoMapper;
import com.zhuiyun.project.api.collectVideo.model.CollectVideoModel;
import com.zhuiyun.project.api.collectVideo.service.CollectVideoService;
import com.zhuiyun.project.api.frontuser.mapper.FrontUserMapper;
import com.zhuiyun.project.api.headportrait.mapper.HeadPortraitMapper;
import com.zhuiyun.project.common.errorCode.CommonException;
import com.zhuiyun.project.common.errorCode.EmErrorCode;
import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.utils.BeanUtils;
import com.zhuiyun.project.utils.validator.ValidatorUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName CollectVideoServiceImpl
 * @Description TODO
 * @Author LXJ
 * @Date 2023/12/28 10:59
 **/
@Service
public class CollectVideoServiceImpl implements CollectVideoService {

    @Autowired
    private CollectVideoMapper collectVideoMapper;

    /**
     * @Author LXJ
     * @Description 根据用户id查询倒序收藏列表
     * @Date 2023/12/28 8:28
     * @Return
     * @param userId
     */
    @Override
    public CommonResult getCollectVideoById(Integer userId,String videoTopic,String videoDesc,Integer Favorites) throws CommonException {
        return CommonResult.ok(collectVideoMapper.getCollectVideoById(userId,videoTopic,videoDesc,Favorites));
    }

    /**
     * @Author LXJ
     * @Description 根据用户id查询正序收藏列表
     * @Date 2023/12/28 8:28
     * @Return
     * @param userId
     */
    @Override
    public CommonResult getCollectVideoByIdASC(Integer userId,String videoTopic,String videoDesc,Integer Favorites) throws CommonException {
        return CommonResult.ok(collectVideoMapper.getCollectVideoByIdASC(userId,videoTopic,videoDesc,Favorites));
    }

    /**
    * @Author XC8
    * @Description 收藏
    * @Date 2024/3/8 9:43
    * @Return com.zhuiyun.project.common.response.CommonResult
    */
    @Override
    public CommonResult addCollectVideo(CollectVideoModel collectVideoModel) throws CommonException {
        if (ValidatorUtil.ValidationObject(collectVideoModel)) {
            CollectVideo collectVideo = new CollectVideo();
            BeanUtils.copy(collectVideoModel, collectVideo);
            int i = collectVideoMapper.addCollectVideo(collectVideo);
            if (i > 0) {
                return CommonResult.ok(EmErrorCode.SAVE_OK);
            } else {
                return CommonResult.error(EmErrorCode.SAVE_ERROR);
            }
        } else {
            return CommonResult.ok(EmErrorCode.SAVE_ERROR);
        }
    }

    /**
    * @Author XC8
    * @Description 取消收藏
    * @Date 2024/3/8 9:44
    * @Return com.zhuiyun.project.common.response.CommonResult
    */
    @Override
    public CommonResult collectVideoDelete(CollectVideoModel collectVideoModel) throws CommonException {
        if(ValidatorUtil.ValidationObject(collectVideoModel)){
            CollectVideo collectVideo = new CollectVideo();
            BeanUtils.copy(collectVideoModel, collectVideo);
            int i=collectVideoMapper.collectVideoDelete(collectVideo);
            if(i>0){
                return CommonResult.ok(EmErrorCode.DELETE_OK);
            }else {
                return CommonResult.error(EmErrorCode.DELETE_ERROR);
            }
        }else {
            return CommonResult.error(EmErrorCode.ID_NULL);
        }
    }


}
